<?php
	function pagelinks(){
	global $page,$count,$currentpage;
        if($page==0){
  
        }else{
	echo "共计<font color=\"#ff0000\">$count</font>条记录";
	echo "<font color=\"#ff0000\">".$currentpage."</font>"."/".$page."页 ";
	echo "<div class='pages'>";
        $pre = $currentpage - 1;
        $next = $currentpage + 1;
        $maxpages = 5;
        $pagepre = 1;
        if($currentpage==1){
        	echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a> ";
        	echo "<a href='".$_SERVER['PHP_SELF']."'><</a> ";
        }else{
        	echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a> ";
        	echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$pre."'><</a> ";
        }
        $pagestart=$currentpage-5;
        if($pagestart>=1&&$pagestart<=$page-5){
        echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$pagestart."'>$pagestart</a> ";
        echo "<a style='margin-right:3px;'>...</a>";
        }       
        if($maxpages>=$page) 
        {$pgstart = 1;$pgend = $page;}
        elseif(($currentpage-$pagepre-1+$maxpages)>$page)
        {$pgstart = $page - $maxpages + 1;$pgend = $page;}
        else{
        $pgstart=(($currentpage<=$pagepre)?1:($currentpage-$pagepre));
        $pgend=(($pgstart==1)?$maxpages:($pgstart+$maxpages-1));
        }
        for($pg=$pgstart;$pg<=$pgend;$pg++){
        if($pg == $currentpage) echo "<a href=\"".$_SERVER['PHP_SELF']."?currentpage=$pg\"><font color=\"#ff0000\">$pg</font></a> ";
        else echo "<a href=\"".$_SERVER['PHP_SELF']."?currentpage=$pg\">$pg</a> ";

        }
        $pageend=$currentpage+8;            
        if($pageend>=$page-8&&$pageend<$page){
        echo "<a>...</a>";
        echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$pageend."'>$pageend</a> ";
	    }
	    if($currentpage == $page){
        	echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$page."'>></a> ";
        	echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$page."'>最后一页</a> ";
        }else{
        	echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$next."'>></a> ";
        	echo "<a href='".$_SERVER['PHP_SELF'].'?currentpage='.$page."'>最后一页</a> ";
        }       
	    echo "</div>";
	}
        }
?>